home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
WINPROGS
/
SAMDU240.ZIP
/
SAMPLE.C
< prev
next >
Wrap
Text File
|
1993-10-01
|
25KB
|
588 lines
#include <Windows.h>
#include <IO.h>
#include <StdIO.h>
#include <StdLib.h>
#include <String.h>
#include "DDrive.h"
#include "DiskDriv.h"
#include "HandleSt.h"
#include "IOStatus.h"
#include "Sample.h"
#ifdef DEBUG
#include "DebugOut.h"
#endif
BOOL bCancel ;
BOOL bFast ;
BOOL bIdle ;
BOOL bQuick ;
BOOL bRegisteredClass ;
char czIconMessage[64] ;
char czNormalMessage[512] ;
FARPROC lpfnHandleStatus ;
HINSTANCE hInstance ;
HWND hWnd ;
UINT nNumberOfDrives ;
UINT nFormatOption ;
UINT nPercentageToColor ;
VOID far * pCDebugOut ;
VOID far * pCVDriveTest ;
VOID far *pCVDrives[26] ;
VOID far * pCDiskImage ;
VOID far * pCDiskTemporary ;
#pragma warning(disable:4100)
int PASCAL WinMain ( HINSTANCE hCurrentInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, UINT nCmdShow)
{
MSG msg;
UINT n ;
#ifdef DEBUG
pCDebugOut = DebugOutCreate ( lpCmdLine ) ;
#endif
bRegisteredClass = FALSE ;
if (!hPrevInstance)
{
if (!InitApplication(hCurrentInstance)) return (FALSE);
bRegisteredClass = TRUE ;
}
if (!InitInstance(hCurrentInstance, nCmdShow)) return (FALSE);
hInstance = hCurrentInstance ;
while (GetMessage(&msg, NULL, NULL, NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if ( nNumberOfDrives )
{
for ( n=0; n<nNumberOfDrives; n++ ) DDriveDelete ( pCVDrives[n] ) ;
}
if ( bRegisteredClass ) UnregisterClass ( "SampleWClass", hInstance ) ;
return ( msg.wParam ) ;
}
#pragma warning(default:4100)
BOOL InitApplication ( HINSTANCE hInstance )
{
WNDCLASS wc;
wc.style = NULL;
wc.lpfnWndProc = MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = "SampleMenu";
wc.lpszClassName = "SampleWClass";
return (RegisterClass(&wc));
}
BOOL InitInstance ( HINSTANCE hInstance, UINT nCmdShow )
{
char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
char czBuffer[256] ;
HMENU hMainMenu ;
HMENU hPopupMenu ;
int i ;
UINT nMenuID ;
UINT nPopupMenuID ;
VOID far * pCVDriveTest ;
hWnd = CreateWindow( "SampleWClass", "Sample SABDU001.DLL Application", WS_OVERLAPPEDWINDOW,
100, 200, 400, 200,
NULL, NULL, hInstance, NULL );
if (!hWnd) return (FALSE);
#ifdef DEBUG
/* The following will be executed if the program is invoked with /D1 on the command line */
/* It will be written to a trace file unless /M1 is also on the command line in which case */
/* it will be displayed in a MessageBox on the screen */
wsprintf ( DebugOutczDebugBuffer(), "This is a sample of a debug trace.\n hWnd = %4.4X", hWnd ) ;
DebugOutOutputIf ( 0x00000001L, DebugOutczDebugBuffer(), "Sample Trace", MB_OK ) ;
#endif
nMenuID = 0 ;
nNumberOfDrives = 0 ;
hMainMenu = GetMenu ( hWnd ) ;
for ( i = 0; i < sizeof(alphabet)/sizeof(alphabet[0])-1 ; i++ )
{
pCVDriveTest = (VOID far *) DDriveCreate ( alphabet[i], (lpfnHANDLESTATUS) lpfnHandleStatus ) ;
if (pCVDriveTest==NULL)
{
; /* Memory problems or worse */
return ( FALSE ) ;
break ;
}
if ((VDriveIsUseable ( pCVDriveTest ))&&(!VDriveIsRemote ( pCVDriveTest ))&&(VDriveIsRemovable ( pCVDriveTest )))
{
pCVDrives[nNumberOfDrives] = pCVDriveTest ;
nNumberOfDrives++ ;
nMenuID += 100 ;
hPopupMenu = CreatePopupMenu () ;
nPopupMenuID = nMenuID ;
AppendMenu ( hPopupMenu, MF_ENABLED|MF_STRING, ++nPopupMenuID, "&Compare" ) ;
nPopupMenuID++ ;
if ( FD0360 & VDriveType ( pCVDriveTest ) ) AppendMenu ( hPopupMenu, MF_ENABLED|MF_STRING, nPopupMenuID, "Format 0&360KB" ) ;
nPopupMenuID++ ;
if ( FD0720 & VDriveType ( pCVDriveTest ) ) AppendMenu ( hPopupMenu, MF_ENABLED|MF_STRING, nPopupMenuID, "Format 0&720KB" ) ;
nPopupMenuID++ ;
if ( FD1200H & VDriveType ( pCVDriveTest ) ) AppendMenu ( hPopupMenu, MF_ENABLED|MF_STRING, nPopupMenuID, "Format 1&200KB" ) ;
nPopupMenuID++ ;
if ( FD1440H & VDriveType ( pCVDriveTest ) ) AppendMenu ( hPopupMenu, MF_ENABLED|MF_STRING, nPopupMenuID, "Format 1&440KB" ) ;
nPopupMenuID++ ;
if ( FD2880H & VDriveType ( pCVDriveTest ) ) AppendMenu ( hPopupMenu, MF_ENABLED|MF_STRING, nPopupMenuID, "Format 2&880KB" ) ;
AppendMenu ( hPopupMenu, MF_ENABLED|MF_STRING, ++nPopupMenuID, "&Read" ) ;
AppendMenu ( hPopupMenu, MF_ENABLED|MF_STRING, ++nPopupMenuID, "&Write" ) ;
czBuffer[0] = '&' ;
czBuffer[1] = VDriveLetter ( pCVDriveTest ) ;
czBuffer[2] = ':' ;
czBuffer[3] = '\0' ;
AppendMenu ( hMainMenu, MF_ENABLED|MF_STRING|MF_POPUP, hPopupMenu, czBuffer ) ;
}
else
{
DDriveDelete ( pCVDriveTest ) ;
}
}
if ( !nNumberOfDrives ) return ( FALSE ) ;
bCancel = FALSE ;
bFast = FALSE ;
bIdle = TRUE ;
bQuick = FALSE ;
pCDiskImage = NULL ;
lpfnHandleStatus = MakeProcInstance ( (FARPROC)HandleStatus, hInstance ) ;
(*(lpfnHANDLESTATUS)lpfnHandleStatus) ( STATUS1_INIT, 0, (UINT)hWnd, (UINT)hInstance, MAKELONG ( TIMER_INTERVAL, 0x0000 ), MAKELONG ( 0x0001, 0x0001 ) ) ;
ShowWindow( hWnd, nCmdShow ) ;
UpdateWindow( hWnd ) ;
return ( TRUE ) ;
}
long FAR PASCAL MainWndProc ( HWND hWnd, UINT nMessage, UINT nParam, LONG lParam )
{
char czMessageBuffer[512] ;
HDC hdc ;
PAINTSTRUCT ps ;
RECT rClient ;
STMESSAGE far *lpstMessage ;
UINT nAction ;
UINT nDrive ;
char czApplicationTitle [] = "SAB Diskette Utility" ;
char czFileName [] = "SABDU.SDU" ;
char czVersionNumber [] = "2.00" ;
char czFullPath [_MAX_PATH] ;
switch ( nMessage )
{
case WM_PAINT:
{
hdc = BeginPaint ( hWnd, &ps ) ;
if (!IsIconic( hWnd ))
{
GetClientRect ( hWnd, &rClient ) ;
if (bIdle)
{
_fstrcpy ( czMessageBuffer, "Please select an item from the menu" ) ;
}
else
{
_fstrcpy ( czMessageBuffer, czNormalMessage ) ;
}
DrawText ( hdc, czMessageBuffer, -1, &rClient, DT_CENTER|DT_WORDBREAK ) ;
}
EndPaint ( hWnd, &ps ) ;
return ( FALSE ) ;
break ;
}
case USR_ACTIVE:
{
bIdle = FALSE ;
lpstMessage = (STMESSAGE far *)lParam ;
if (lpstMessage->pIconMessage) _fstrcpy ( czIconMessage, lpstMessage->pIconMessage ) ;
if (lpstMessage->pNormalMessage) _fstrcpy ( czNormalMessage, lpstMessage->pNormalMessage ) ;
nPercentageToColor = lpstMessage->nPercentageToColor ;
InvalidateRect ( hWnd, NULL, TRUE ) ;
UpdateWindow ( hWnd ) ;
return ( !bCancel ) ;
break ;
}
case USR_UPDATE:
{
bIdle = FALSE ;
lpstMessage = (STMESSAGE far *)lParam ;
if (lpstMessage->pIconMessage) _fstrcpy ( czIconMessage, lpstMessage->pIconMessage ) ;
if (lpstMessage->pNormalMessage) _fstrcpy ( czNormalMessage, lpstMessage->pNormalMessage ) ;
nPercentageToColor = lpstMessage->nPercentageToColor ;
InvalidateRect ( hWnd, NULL, FALSE ) ;
UpdateWindow ( hWnd ) ;
return ( !bCancel ) ;
break ;
}
case USR_INACTIVE:
{
bIdle = TRUE ;
InvalidateRect ( hWn